package cc.vv.btpartyjob.partyservice.activity

import android.text.TextUtils
import android.view.View
import android.view.WindowManager
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.global.UserInfoSharePreKey
import cc.vv.baselibrary.util.LKPrefUtil
import cc.vv.baselibrary.util.LKToastUtil
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.binder.BaseBinder
import cc.vv.btpartyjob.partyservice.R
import cc.vv.btpartyjob.partyservice.delegate.SubmitMessageActivityDelegate
import cc.vv.btpartyjob.partyservice.module.resp.SubMessageResponseObj
import cc.vv.btpartyjob.partyservice.server.DataPartyServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 发布留言
 * Created by Chen.qi on 2018/11/7.
 */
class SubmitMessageActivity : BaseActivityMVP<SubmitMessageActivityDelegate>() {

    private var name: String? = null

    private var tel: String? = null

    override fun initData() {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
        viewDelegate?.setTopBarTitle("发表留言")

        name = LKPrefUtil.getString(UserInfoSharePreKey.USER_NAME, "")
        tel = LKPrefUtil.getString(UserInfoSharePreKey.USER_TEL_PHONE, "")

        viewDelegate?.setName(name)
        viewDelegate?.setMobile(tel)
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {

                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
            }
        })


        viewDelegate?.setOnClickListener(View.OnClickListener {
            //提交

            val title = viewDelegate?.getTitle()
            val content = viewDelegate?.getContent()
            if (TextUtils.isEmpty(title) || TextUtils.isEmpty(content)) {
                LKToastUtil.showToastShort("请将数据填写完整")
                return@OnClickListener
            }
            DataPartyServer.subMessageHttp(name, tel, title, content, true)
        }, R.id.rl_asm_submit)
    }

    override fun getDelegateClass(): Class<SubmitMessageActivityDelegate> {
        return SubmitMessageActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is SubMessageResponseObj -> {
                LKToastUtil.showToastShort("发表成功,等待审核")
                finish()
            }
        }
    }
}